//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

package uxgenes.ext.camera;

import uxgenes.core.Logger;
import android.graphics.SurfaceTexture;
import android.view.SurfaceHolder;
import android.view.SurfaceView;


//
// Camera Texture Preview (API 11)
//
public final class CameraTexturePreview 	extends 	SurfaceTexture
											implements 	ICameraSurface,
														SurfaceTexture.OnFrameAvailableListener,
														SurfaceHolder.Callback
{
// constants //
	private static final String	TAG = "CameraTexturePreview";
	
	
// variables //
	private UXCamera	_camera = null;

	
// methods //
	public CameraTexturePreview (int texName, SurfaceView glSurfaceView)
	{
		super(texName);
	}

	
// ICameraSurface //
	
	// IsCreated
	public final boolean IsCreated ()
	{
		return true;
	}

	
	// SetCamera
	public final void	SetCamera (UXCamera cam)
	{
		_camera = cam;
	}
	
	
	// OnStartPreview
	public final void OnStartPreview ()
	{
		try {
			_camera.GetHwCamera().setPreviewTexture( this );
		}
		catch (Exception e) {
			Logger.OnCatchException( TAG, e );
		}
	}
	
	
	// OnStopPreview
	public final void OnStopPreview ()
	{
		try {
			_camera.GetHwCamera().setPreviewTexture( null );
		}
		catch (Exception e) {
			Logger.OnCatchException( TAG, e );
		}
	}

	
// SurfaceTexture.OnFrameAvailableListener //
	
	// onFrameAvailable
	public final void onFrameAvailable (SurfaceTexture surfaceTexture)
	{
		if ( _camera != null ) {
			_camera.OnFrameAvailable( surfaceTexture );
		}
	}


// SurfaceHolder.Callback //
	
	// surfaceChanged
	public final void surfaceChanged (SurfaceHolder holder, int format, int width, int height)
	{
	}


	// surfaceCreated
	public final void surfaceCreated (SurfaceHolder holder)
	{
	}

	
	// surfaceDestroyed
	public final void surfaceDestroyed (SurfaceHolder holder)
	{
	}

}
